﻿package mortal.game.scene3D.map3D
{
    import com.gengine.global.*;
    import com.gengine.utils.*;
    import flash.geom.*;
    import mortal.game.scene3D.player.entity.*;
    import mortal.game.scene3D.util.*;

    public class Speed extends Object
    {
        private var _distance:Number;
        private var _xSpeed:Number;
        private var _ySpeed:Number;
        private var _radians:Number;
        private var _direction:Number;
        private var _speed:Number = 5;
        private var _timeSpeed:Number = 0;
        public var attackDistance:int = 5;
        private var _startPoint:Point;
        private var _endPoint:Point;
        private const _interval:Number = 16.6667;
        public var player:MovePlayer;
        public static var SpeedUp:Number = 1;

        public function Speed() : void
        {
            this._startPoint = new Point();
            this._endPoint = new Point();
            return;
        }// end function

        public function get timeSpeed() : Number
        {
            return this._timeSpeed;
        }// end function

        public function set timeSpeed(param1:Number) : void
        {
            this._timeSpeed = param1 / 1000;
            this._speed = param1 / Global.stage.frameRate;
            return;
        }// end function

        public function get speed() : Number
        {
            return this._speed;
        }// end function

        public function get ySpeed() : Number
        {
            return this._ySpeed;
        }// end function

        public function get xSpeed() : Number
        {
            return this._xSpeed;
        }// end function

        public function setPoint(param1:Number, param2:Number, param3:Number, param4:Number) : void
        {
            this._startPoint.x = param1;
            this._startPoint.y = param2;
            this._endPoint.x = param3;
            this._endPoint.y = param4;
            this.updateSpeed();
            return;
        }// end function

        public function get isArrive() : Boolean
        {
            return this.distance < this.attackDistance * 1.3;
        }// end function

        public function update(param1:Number, param2:Number) : void
        {
            this._startPoint.x = param1;
            this._startPoint.y = param2;
            this.updateSpeed();
            return;
        }// end function

        private function updateSpeed() : void
        {
            this._radians = MathUitl.getRadiansByPoint(this._startPoint, this._endPoint);
            this._direction = MathUitl.getAngle(this._radians);
            this._speed = this._timeSpeed * MoveUtil.speedInterval;
            this._xSpeed = this._speed * Math.cos(this._radians) * SpeedUp;
            this._ySpeed = this._speed * Math.sin(this._radians) * SpeedUp;
            return;
        }// end function

        public function setSpeedXY(param1:Number, param2:Number) : void
        {
            this._xSpeed = param1;
            this._ySpeed = param2;
            return;
        }// end function

        public function get radians() : Number
        {
            return this._radians;
        }// end function

        public function get distance() : Number
        {
            return Point.distance(this._endPoint, this._startPoint);
        }// end function

        public function get direction() : Number
        {
            return this._direction;
        }// end function

    }
}
